﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Lk.Web.Models;
using Lk.Common;
using Lk.Common.Cache;
using Lk.Common.Redis;
using Lk.Web.Filter;

namespace Lk.Web.Controllers
{

    [FieldFilter]
    public class HomeController : Controller
    {
        private readonly AppConfigurtaionServices _appConfigurtaionServices;
        private readonly ICacheService _cacheService;
        public HomeController(AppConfigurtaionServices appConfigurtaionServices, ICacheService cacheService)
        {
            _appConfigurtaionServices = appConfigurtaionServices;
            _cacheService = cacheService;
        }
        public IActionResult Index()
        {

            var rootDirectory = AppContext.BaseDirectory;

            _cacheService.Add("test", "test一下");

            var test = _cacheService.Get<string>("test");
            return View();
        }

        public IActionResult About()
        {


            var config = _appConfigurtaionServices.AppConfigurations.FileUpPath;
        
            ViewData["Message"] = config;


            return View();
        }


        public IActionResult Test(string v)
        {

            
            try
            {
               // int s = int.Parse(v);
            }
            catch (Exception)
            {
                return new StatusCodeResult(429);
            }
            return Content(v);
        }
        public IActionResult Contact()
        {
            ViewData["Message"] = "Your contact page.";

            return View();
        }

        public IActionResult Privacy()
        {
            return View();
        }

        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }

        [Route("error/404")]
        public IActionResult Error404()
        {
            return View();
        }

        [Route("error/{code:int}")]
        public IActionResult Error(int code)
        {
            // handle different codes or just return the default error view
            return View();
        }
    }
}
